#ifndef _UART_H
#define _UART_H

#include "main.h"

#define UART_HT             HT_UART0
#define UART_AF_PORT        AFIO_PORT(C)
#define UART_Tx_AF_PIN      AFIO_PIN(4)
#define UART_Rx_AF_PIN      AFIO_PIN(5)

#define UART_MAXBUFFLEN     128 //定义串口的接收缓冲

typedef HT_USART_TypeDef *USART_T;//定义结构体支配接口

typedef enum
{
    UART_COM = 0,//串口调试以及打印口
    UART_NUM
} uart_chn;

typedef struct _uart_ {
    USART_T     regs;
    uint32_t    baud;
    uint16_t    fifo_txlen;
    uint16_t    fifo_rxlen;
    uint8_t     tx_busy;
    uint8_t     rx_busy;
    bfifo_t     fifo_tx;
    bfifo_t     fifo_rx;
    Timer_t     uart_idle;
} uart_t;

void uart_init(void);
int uart_send(uint8_t chn, const void *dat, int size);
int uart_recv(uint8_t chn, void *dat, int size);
void uart_proc(void);
void uart_test(void);

#endif
